/*      */ package dm.sql;
/*      */ 
/*      */ import dm.jdbc.dataConvertion.CType2JType;
/*      */ import dm.jdbc.dataConvertion.Convertion;
/*      */ import dm.jdbc.dbaccess.Const;
/*      */ import dm.jdbc.dbaccess.DBError;
/*      */ import dm.jdbc.desc.BaseInfo;
/*      */ import dm.jdbc.desc.CommDesc;
/*      */ import dm.jdbc.desc.DTypeInfo;
/*      */ import dm.jdbc.driver.DmBigDecBinder;
/*      */ import dm.jdbc.driver.DmBooleanBinder;
/*      */ import dm.jdbc.driver.DmByteArrBinder;
/*      */ import dm.jdbc.driver.DmByteBinder;
/*      */ import dm.jdbc.driver.DmDateBinder;
/*      */ import dm.jdbc.driver.DmDoubleBinder;
/*      */ import dm.jdbc.driver.DmFloatBinder;
/*      */ import dm.jdbc.driver.DmIntBinder;
/*      */ import dm.jdbc.driver.DmIntvDTBinder;
/*      */ import dm.jdbc.driver.DmIntvYMBinder;
/*      */ import dm.jdbc.driver.DmLongBinder;
/*      */ import dm.jdbc.driver.DmShortBinder;
/*      */ import dm.jdbc.driver.DmStringBinder;
/*      */ import dm.jdbc.driver.DmTimeBinder;
/*      */ import dm.jdbc.driver.DmTimestampBinder;
/*      */ import dm.jdbc.driver.DmdbBlob;
/*      */ import dm.jdbc.driver.DmdbClob;
/*      */ import dm.jdbc.driver.DmdbConnection_bs;
/*      */ import dm.jdbc.driver.DmdmTimeBinder;
/*      */ import dm.jdbc.util.Comparison;
/*      */ import java.math.BigDecimal;
/*      */ import java.sql.Blob;
/*      */ import java.sql.Clob;
/*      */ import java.sql.SQLData;
/*      */ import java.sql.SQLException;
/*      */ import java.sql.Time;
/*      */ import java.sql.Timestamp;
/*      */ import java.util.Map;
/*      */ import java.util.ResourceBundle;
/*      */ import java.util.Vector;
/*      */ 
/*      */ 
/*      */ 
/*      */ public class TypeData
/*      */ {
/*   45 */   Object m_dumyData = null;
/*   46 */   int m_offset = 0;
/*      */   
/*      */   int m_bufLen;
/*   49 */   byte[] m_dataBuf = null;
/*      */   
/*   51 */   byte[] m_objBlobDescBuf = null;
/*   52 */   boolean m_isFromBlob = false;
/*   53 */   int m_packid = -1;
/*   54 */   Vector m_objRefArr = new Vector(0);
/*      */   
/*      */   TypeData(Object val, byte[] dataBuf) {
/*   57 */     this.m_dumyData = null;
/*      */     
/*   59 */     this.m_dumyData = val;
/*   60 */     this.m_offset = 0;
/*   61 */     this.m_bufLen = 0;
/*   62 */     this.m_dataBuf = dataBuf;
/*      */   }
/*      */   
/*      */   public static TypeData[] toStruct(Object[] objArr, TypeDescriptor desc)
/*      */     throws SQLException
/*      */   {
/*   68 */     int size = desc.getStrctMemSize();
/*   69 */     TypeData[] retData = new TypeData[size];
/*      */     
/*   71 */     for (int i = 0; i < size; i++) {
/*   72 */       switch (desc.m_fieldsObj[i].getDType()) {
/*      */       case 119: 
/*      */       case 121: 
/*   75 */         if (objArr[i] == null) {
/*   76 */           retData[i] = new TypeData(null, null);
/*      */ 
/*      */ 
/*      */         }
/*   80 */         else if ((objArr[i] instanceof STRUCT)) {
/*   81 */           retData[i] = new TypeData(objArr[i], null);
/*   82 */         } else if ((objArr[i] instanceof SQLData)) {
/*   83 */           String typeName = ((SQLData)objArr[i]).getSQLTypeName();
/*   84 */           if (typeName != null)
/*      */           {
/*   86 */             if (typeName.equals(desc.m_fieldsObj[i].getFulName())) {
/*   87 */               DmdbSQLOutput stream = new DmdbSQLOutput();
/*   88 */               ((SQLData)objArr[i]).writeSQL(stream);
/*   89 */               STRUCT struct = new STRUCT(toStruct(
/*   90 */                 stream.getAttribs(), desc.m_fieldsObj[i]), 
/*   91 */                 desc.m_fieldsObj[i]);
/*   92 */               retData[i] = new TypeData(struct, null);
/*   93 */               continue; } }
/*   94 */           DBError.throwSQLException(6007);
/*      */         }
/*      */         else {
/*   97 */           retData[i] = new TypeData(new STRUCT(toStruct(
/*   98 */             (Object[])objArr[i], desc.m_fieldsObj[i]), 
/*   99 */             desc.m_fieldsObj[i]), null); }
/*  100 */         break;
/*      */       
/*      */       case 117: 
/*      */       case 122: 
/*  104 */         if (objArr[i] == null) {
/*  105 */           retData[i] = new TypeData(null, null);
/*      */ 
/*      */ 
/*      */         }
/*  109 */         else if ((objArr[i] instanceof ARRAY)) {
/*  110 */           retData[i] = ((TypeData)objArr[i]);
/*      */         } else
/*  112 */           retData[i] = new TypeData(new ARRAY(toArray(
/*  113 */             (Object[])objArr[i], desc.m_fieldsObj[i]), 
/*  114 */             desc.m_fieldsObj[i]), null);
/*  115 */         break;
/*      */       case 118: case 120: 
/*      */       default: 
/*  118 */         retData[i] = toMemberObj(objArr[i], desc.m_fieldsObj[i]);
/*      */       }
/*      */       
/*      */     }
/*      */     
/*  123 */     return retData;
/*      */   }
/*      */   
/*      */   public static TypeData[] toArray(Object[] objArr, TypeDescriptor desc)
/*      */     throws SQLException
/*      */   {
/*  129 */     int size = objArr.length;
/*  130 */     TypeData[] retData = new TypeData[size];
/*  131 */     for (int i = 0; i < size; i++) {
/*  132 */       switch (desc.m_arrObj.getDType()) {
/*      */       case 119: 
/*      */       case 121: 
/*  135 */         if (objArr[i] == null) {
/*  136 */           retData[i] = new TypeData(null, null);
/*      */ 
/*      */ 
/*      */         }
/*  140 */         else if ((objArr[i] instanceof STRUCT)) {
/*  141 */           retData[i] = new TypeData(objArr[i], null);
/*      */         } else {
/*  143 */           retData[i] = new TypeData(
/*  144 */             new STRUCT(toStruct((Object[])objArr[i], 
/*  145 */             desc.m_arrObj), desc.m_arrObj), null);
/*      */         }
/*  147 */         break;
/*      */       
/*      */       case 117: 
/*      */       case 122: 
/*  151 */         if (objArr[i] == null) {
/*  152 */           retData[i] = new TypeData(null, null);
/*      */ 
/*      */ 
/*      */         }
/*  156 */         else if ((objArr[i] instanceof ARRAY)) {
/*  157 */           retData[i] = new TypeData(objArr[i], null);
/*      */         }
/*      */         else {
/*  160 */           if ((!(objArr[i] instanceof Object[])) && 
/*  161 */             (desc.m_arrObj.m_arrObj != null)) {
/*  162 */             objArr[i] = makeupObjToArr(objArr[i], desc.m_arrObj);
/*      */           }
/*  164 */           retData[i] = new TypeData(
/*  165 */             new ARRAY(toArray((Object[])objArr[i], 
/*  166 */             desc.m_arrObj), desc.m_arrObj), null);
/*      */         }
/*  168 */         break;
/*      */       case 118: case 120: 
/*      */       default: 
/*  171 */         retData[i] = toMemberObj(objArr[i], desc.m_arrObj);
/*      */       }
/*      */       
/*      */     }
/*      */     
/*  176 */     return retData;
/*      */   }
/*      */   
/*      */   private static Object[] makeupObjToArr(Object obj, TypeDescriptor objDesc)
/*      */     throws SQLException
/*      */   {
/*  182 */     int arrType = objDesc.getDType();
/*  183 */     boolean dynamic = true;
/*  184 */     int arrLen = 0;
/*  185 */     if (arrType == 122) {
/*  186 */       dynamic = false;
/*  187 */       arrLen = objDesc.m_length;
/*      */     }
/*      */     
/*  190 */     int subType = objDesc.m_arrObj.getDTypeInfo().getDType();
/*  191 */     if ((subType == 17) || 
/*  192 */       (subType == 18) || 
/*  193 */       (subType == 3) || 
/*  194 */       (subType == 4)) {
/*  195 */       String strRet = "";
/*  196 */       if ((obj instanceof Integer)) {
/*  197 */         strRet = Integer.toBinaryString(((Integer)obj).intValue());
/*  198 */       } else if ((obj instanceof Long)) {
/*  199 */         strRet = Long.toBinaryString(((Long)obj).longValue());
/*  200 */       } else if ((obj instanceof String)) {
/*  201 */         strRet = (String)obj;
/*      */       } else {
/*  203 */         DBError.throwSQLException(6007);
/*      */       }
/*  205 */       int prec = dynamic ? strRet.length() : arrLen;
/*  206 */       Object[] ret = new Object[prec];
/*  207 */       byte[] rs = Convertion.String_char_2CType(strRet, prec, subType, 
/*  208 */         objDesc.getServerEncoding());
/*  209 */       for (int i = 0; i < prec; i++) {
/*  210 */         ret[i] = new Byte(rs[i]);
/*      */       }
/*  212 */       return ret;
/*      */     }
/*      */     
/*  215 */     DBError.throwSQLException(6036);
/*  216 */     return null;
/*      */   }
/*      */   
/*      */   private static TypeData toMemberObj(Object mem, TypeDescriptor desc) throws SQLException
/*      */   {
/*  221 */     Object retObj = mem;
/*  222 */     byte[] bs = null;
/*  223 */     int scale = desc.m_dTypeInfo.getScale();
/*  224 */     int prec = desc.m_dTypeInfo.getPrec();
/*  225 */     int dtype = desc.m_dTypeInfo.getDType();
/*  226 */     short ltz = desc.m_conn.getTz();
/*  227 */     short dbTz = (short)desc.m_conn.getDbTz();
/*  228 */     String serverEncoding = desc.m_conn.getServerEncoding();
/*  229 */     if (mem == null) {
/*  230 */       return new TypeData(null, null);
/*      */     }
/*      */     
/*  233 */     if ((mem instanceof String)) {
/*  234 */       bs = DmStringBinder.toDbBytes((String)mem, dtype, prec, scale, 
/*  235 */         serverEncoding, ltz, dbTz);
/*  236 */     } else if ((mem instanceof Integer)) {
/*  237 */       bs = DmIntBinder.toDbBytes(((Integer)mem).intValue(), dtype, prec, 
/*  238 */         scale, serverEncoding, ltz, dbTz);
/*  239 */     } else if ((mem instanceof Short)) {
/*  240 */       bs = DmShortBinder.toDbBytes(((Short)mem).shortValue(), dtype, 
/*  241 */         prec, scale, serverEncoding, ltz, dbTz);
/*  242 */     } else if ((mem instanceof Long)) {
/*  243 */       bs = DmLongBinder.toDbBytes(((Long)mem).longValue(), dtype, prec, 
/*  244 */         scale, serverEncoding, ltz, dbTz);
/*  245 */     } else if ((mem instanceof Double)) {
/*  246 */       bs = DmDoubleBinder.toDbBytes(((Double)mem).doubleValue(), dtype, 
/*  247 */         prec, scale, serverEncoding);
/*  248 */     } else if ((mem instanceof Float)) {
/*  249 */       bs = DmFloatBinder.toDbBytes(((Float)mem).floatValue(), dtype, 
/*  250 */         prec, scale, serverEncoding);
/*  251 */     } else if ((mem instanceof Byte)) {
/*  252 */       bs = DmByteBinder.toDbBytes(((Byte)mem).byteValue(), dtype, prec, 
/*  253 */         scale, serverEncoding, ltz, dbTz);
/*  254 */     } else if ((mem instanceof BigDecimal)) {
/*  255 */       bs = DmBigDecBinder.toDbBytes((BigDecimal)mem, dtype, prec, scale, 
/*  256 */         serverEncoding);
/*  257 */     } else if ((mem instanceof Number)) {
/*  258 */       BigDecimal tmp = new BigDecimal(String.valueOf(mem));
/*  259 */       bs = DmBigDecBinder.toDbBytes(tmp, dtype, prec, scale, 
/*  260 */         serverEncoding);
/*  261 */     } else if ((mem instanceof java.sql.Date)) {
/*  262 */       bs = DmDateBinder.toDbBytes((java.sql.Date)mem, dtype, prec, scale, 
/*  263 */         serverEncoding, ltz, dbTz);
/*  264 */     } else if ((mem instanceof Time)) {
/*  265 */       bs = DmTimeBinder.toDbBytes((Time)mem, dtype, prec, scale, 
/*  266 */         serverEncoding, ltz, dbTz);
/*  267 */     } else if ((mem instanceof Timestamp)) {
/*  268 */       bs = DmTimestampBinder.toDbBytes((Timestamp)mem, dtype, prec, 
/*  269 */         scale, serverEncoding, ltz, dbTz);
/*  270 */     } else if ((mem instanceof Blob)) {
/*  271 */       if (dtype != 12) {
/*  272 */         DBError.throwSQLException(6007);
/*      */       }
/*  274 */       bs = null;
/*  275 */     } else if ((mem instanceof Clob)) {
/*  276 */       if (dtype != 19) {
/*  277 */         DBError.throwSQLException(6007);
/*      */       }
/*  279 */       bs = null;
/*  280 */     } else if ((mem instanceof byte[])) {
/*  281 */       bs = DmByteArrBinder.toDbBytes((byte[])mem, dtype, prec);
/*  282 */     } else if ((mem instanceof Boolean)) {
/*  283 */       bs = DmBooleanBinder.toDbBytes(((Boolean)mem).booleanValue(), 
/*  284 */         dtype, prec, scale, serverEncoding);
/*  285 */     } else if ((mem instanceof DmdbIntervalDT)) {
/*  286 */       bs = DmIntvDTBinder.toDbBytes((DmdbIntervalDT)mem, dtype, prec, 
/*  287 */         scale, serverEncoding);
/*  288 */     } else if ((mem instanceof DmdbIntervalYM)) {
/*  289 */       bs = DmIntvYMBinder.toDbBytes((DmdbIntervalYM)mem, dtype, prec, 
/*  290 */         scale, serverEncoding);
/*  291 */     } else if ((mem instanceof DmdbTime)) {
/*  292 */       bs = DmdmTimeBinder.toDbBytes((DmdbTime)mem, dtype, prec, scale, 
/*  293 */         serverEncoding, ltz, dbTz);
/*  294 */     } else if ((mem instanceof DmdbTimeZone)) {
/*  295 */       switch (dtype) {
/*      */       case 0: 
/*      */       case 1: 
/*      */       case 2: 
/*      */       case 19: 
/*  300 */         String str = String.valueOf(mem);
/*  301 */         bs = DmStringBinder.toDbBytes(str, dtype, prec, scale, 
/*  302 */           serverEncoding, ltz, dbTz);
/*  303 */         break;
/*      */       case 22: 
/*  305 */         bs = Convertion.TimeZoneToByteArray((DmdbTimeZone)mem);
/*  306 */         break;
/*      */       case 23: 
/*  308 */         bs = Convertion.DateTimeZoneToByteArray((DmdbTimeZone)mem);
/*  309 */         break;
/*      */       
/*      */       default: 
/*  312 */         DBError.throwSQLException(6007);
/*      */         
/*  314 */         break; } } else if ((mem instanceof Character)) {
/*  315 */       String str = String.valueOf(mem);
/*  316 */       bs = DmStringBinder.toDbBytes(str, dtype, prec, scale, 
/*  317 */         serverEncoding, ltz, dbTz);
/*  318 */     } else if ((mem instanceof java.util.Date)) {
/*  319 */       java.sql.Date date = new java.sql.Date(
/*  320 */         ((java.util.Date)mem).getTime());
/*  321 */       bs = DmDateBinder.toDbBytes(date, dtype, prec, scale, 
/*  322 */         serverEncoding, ltz, dbTz);
/*      */     } else {
/*  324 */       DBError.throwUnsupportedSQLException();
/*      */     }
/*      */     
/*  327 */     return new TypeData(retObj, bs);
/*      */   }
/*      */   
/*      */   private static byte[] typeDataToBytes(TypeData data, TypeDescriptor desc) throws SQLException
/*      */   {
/*  332 */     int dType = desc.getDType();
/*  333 */     byte[] innerData = null;
/*  334 */     if (data.m_dumyData == null) {
/*  335 */       innerData = realocBuffer(null, 0, 2);
/*  336 */       Convertion.setByte(innerData, 0, (byte)0);
/*  337 */       Convertion.setByte(innerData, 1, (byte)0);
/*  338 */       return innerData;
/*      */     }
/*      */     
/*  341 */     byte[] result = null;
/*  342 */     int offset = 0;
/*  343 */     switch (dType)
/*      */     {
/*      */     case 117: 
/*  346 */       innerData = arrayToBytes((ARRAY)data.m_dumyData, desc);
/*  347 */       result = realocBuffer(null, 0, innerData.length + 1 + 
/*  348 */         1);
/*      */       
/*  350 */       Convertion.setByte(result, 0, (byte)0);
/*  351 */       offset = 1;
/*      */       
/*  353 */       Convertion.setByte(result, offset, (byte)1);
/*  354 */       offset++;
/*      */       
/*  356 */       System.arraycopy(innerData, 0, result, offset, innerData.length);
/*  357 */       return result;
/*      */     
/*      */ 
/*      */     case 122: 
/*  361 */       innerData = sarrayToBytes((ARRAY)data.m_dumyData, desc);
/*  362 */       result = realocBuffer(null, 0, innerData.length + 1 + 
/*  363 */         1);
/*      */       
/*  365 */       Convertion.setByte(result, 0, (byte)0);
/*  366 */       offset = 1;
/*      */       
/*  368 */       Convertion.setByte(result, offset, (byte)1);
/*  369 */       offset++;
/*      */       
/*  371 */       System.arraycopy(innerData, 0, result, offset, innerData.length);
/*  372 */       return result;
/*      */     
/*      */ 
/*      */     case 119: 
/*  376 */       innerData = objToBytes((STRUCT)data.m_dumyData, desc);
/*  377 */       result = realocBuffer(null, 0, innerData.length + 1 + 
/*  378 */         1);
/*      */       
/*  380 */       Convertion.setByte(result, 0, (byte)0);
/*  381 */       offset = 1;
/*      */       
/*  383 */       Convertion.setByte(result, offset, (byte)1);
/*  384 */       offset++;
/*      */       
/*  386 */       System.arraycopy(innerData, 0, result, offset, innerData.length);
/*  387 */       return result;
/*      */     
/*      */ 
/*      */     case 121: 
/*  391 */       innerData = recordToBytes((STRUCT)data.m_dumyData, desc);
/*  392 */       result = realocBuffer(null, 0, innerData.length + 1 + 
/*  393 */         1);
/*      */       
/*  395 */       Convertion.setByte(result, 0, (byte)0);
/*  396 */       offset = 1;
/*      */       
/*  398 */       Convertion.setByte(result, offset, (byte)1);
/*  399 */       offset++;
/*      */       
/*  401 */       System.arraycopy(innerData, 0, result, offset, innerData.length);
/*  402 */       return result;
/*      */     
/*      */     case 12: 
/*      */     case 19: 
/*  406 */       innerData = convertLobToBytes(data.m_dumyData, desc.getDTypeInfo(), 
/*  407 */         desc.getServerEncoding());
/*      */       
/*  409 */       result = realocBuffer(null, 0, innerData.length + 1 + 
/*  410 */         1);
/*      */       
/*      */ 
/*  413 */       Convertion.setByte(result, 0, (byte)0);
/*  414 */       offset = 1;
/*      */       
/*      */ 
/*  417 */       Convertion.setByte(result, offset, (byte)1);
/*  418 */       offset++;
/*      */       
/*  420 */       System.arraycopy(innerData, 0, result, offset, innerData.length);
/*  421 */       return result;
/*      */     
/*      */     case 13: 
/*  424 */       innerData = realocBuffer(null, 0, 2);
/*  425 */       Convertion.setByte(innerData, 0, (byte)0);
/*  426 */       if ((data.m_dataBuf != null) && (data.m_dataBuf.length > 0)) {
/*  427 */         Convertion.setByte(innerData, 1, data.m_dataBuf[0]);
/*      */       } else {
/*  429 */         Convertion.setByte(innerData, 1, (byte)0);
/*      */       }
/*  431 */       return innerData;
/*      */     }
/*      */     
/*      */     
/*      */ 
/*      */ 
/*  437 */     innerData = data.m_dataBuf;
/*  438 */     result = realocBuffer(null, 0, innerData.length + 1 + 
/*  439 */       1 + 2);
/*      */     
/*      */ 
/*      */ 
/*  443 */     Convertion.setByte(result, 0, (byte)0);
/*  444 */     offset = 1;
/*      */     
/*      */ 
/*  447 */     Convertion.setByte(result, offset, (byte)1);
/*  448 */     offset++;
/*      */     
/*  450 */     Convertion.setShort(result, offset, (short)innerData.length);
/*  451 */     offset += 2;
/*      */     
/*  453 */     System.arraycopy(innerData, 0, result, offset, innerData.length);
/*      */     
/*  455 */     return result;
/*      */   }
/*      */   
/*      */   private static byte[] convertLobToBytes(Object value, DTypeInfo dtypeInfo, String serverEncoding)
/*      */     throws SQLException
/*      */   {
/*  461 */     byte[] tmp = null;
/*  462 */     byte[] ret = null;
/*  463 */     int len = 0;
/*  464 */     if (dtypeInfo.getDType() == 12) {
/*  465 */       DmdbBlob lob = (DmdbBlob)value;
/*  466 */       len = lob.getLobLen();
/*  467 */       tmp = lob.getBytes(1L, len);
/*  468 */       ret = new byte[len + 4];
/*  469 */       Convertion.setInt(ret, 0, len);
/*  470 */       System.arraycopy(tmp, 0, ret, 4, len);
/*  471 */       return ret;
/*      */     }
/*      */     
/*  474 */     if (dtypeInfo.getDType() == 19) {
/*  475 */       DmdbClob lob = (DmdbClob)value;
/*  476 */       len = lob.getLobLen();
/*  477 */       String subString = lob.getSubString(1L, len);
/*  478 */       tmp = Convertion.getBytes(subString, serverEncoding);
/*  479 */       ret = new byte[tmp.length + 4];
/*  480 */       Convertion.setInt(ret, 0, len);
/*  481 */       System.arraycopy(tmp, 0, ret, 4, len);
/*  482 */       return ret;
/*      */     }
/*      */     
/*  485 */     DBError.throwSQLException(6007);
/*  486 */     return null;
/*      */   }
/*      */   
/*      */   public static byte[] sarrayToBytes(ARRAY data, TypeDescriptor desc) throws SQLException
/*      */   {
/*  491 */     int realLen = data.m_arrData.length;
/*  492 */     byte[][] results = new byte[realLen][];
/*  493 */     byte[] rdata = null;
/*      */     
/*      */ 
/*  496 */     if (desc.getObjId() == 4) {
/*  497 */       return ctlnToBytes(data, desc);
/*      */     }
/*      */     
/*  500 */     int totalLen = 0;
/*  501 */     for (int i = 0; i < realLen; i++) {
/*  502 */       results[i] = typeDataToBytes(data.m_arrData[i], desc.m_arrObj);
/*  503 */       totalLen += results[i].length;
/*      */     }
/*      */     
/*      */ 
/*  507 */     totalLen += 8;
/*  508 */     rdata = realocBuffer(null, 0, totalLen);
/*  509 */     int off = 0;
/*      */     
/*  511 */     Convertion.setInt(rdata, off, totalLen);
/*  512 */     off += 4;
/*      */     
/*      */ 
/*  515 */     Convertion.setInt(rdata, off, data.m_arrDesc.getLength());
/*  516 */     off += 4;
/*      */     
/*  518 */     for (int i = 0; i < realLen; i++) {
/*  519 */       System.arraycopy(results[i], 0, rdata, off, results[i].length);
/*  520 */       off += results[i].length;
/*      */     }
/*      */     
/*  523 */     return rdata;
/*      */   }
/*      */   
/*      */   public static byte[] ctlnToBytes(ARRAY data, TypeDescriptor desc) throws SQLException
/*      */   {
/*  528 */     byte[][] results = new byte[data.m_arrData.length][];
/*  529 */     byte[] rdata = null;
/*      */     
/*      */ 
/*  532 */     int totalLen = 0;
/*  533 */     totalLen = 5;
/*      */     
/*  535 */     totalLen += 8;
/*      */     
/*  537 */     for (int i = 0; i < data.m_arrData.length; i++) {
/*  538 */       results[i] = typeDataToBytes(data.m_arrData[i], desc.m_arrObj);
/*  539 */       totalLen += results[i].length;
/*      */     }
/*      */     
/*  542 */     rdata = realocBuffer(null, 0, totalLen);
/*      */     
/*  544 */     int offset = 0;
/*      */     
/*  546 */     Convertion.setByte(rdata, offset, (byte)0);
/*  547 */     offset++;
/*      */     
/*      */ 
/*  550 */     offset += 4;
/*      */     
/*  552 */     Convertion.setShort(rdata, offset, (short)desc.getCltnType());
/*  553 */     offset += 2;
/*      */     
/*  555 */     Convertion.setShort(rdata, offset, (short)desc.m_arrObj.getDType());
/*  556 */     offset += 2;
/*      */     
/*  558 */     Convertion.setInt(rdata, offset, data.m_arrData.length);
/*  559 */     offset += 4;
/*      */     
/*  561 */     for (int i = 0; i < data.m_arrData.length; i++) {
/*  562 */       System.arraycopy(results[i], 0, rdata, offset, results[i].length);
/*  563 */       offset += results[i].length;
/*      */     }
/*      */     
/*      */ 
/*  567 */     Convertion.setInt(rdata, 1, offset);
/*      */     
/*  569 */     return rdata;
/*      */   }
/*      */   
/*      */   public static byte[] arrayToBytes(ARRAY data, TypeDescriptor desc) throws SQLException
/*      */   {
/*  574 */     byte[][] results = new byte[data.m_arrData.length][];
/*  575 */     byte[] rdata = null;
/*      */     
/*  577 */     if (desc.getObjId() == 4) {
/*  578 */       return ctlnToBytes(data, desc);
/*      */     }
/*      */     
/*      */ 
/*  582 */     int totalLen = 0;
/*  583 */     for (int i = 0; i < data.m_arrData.length; i++) {
/*  584 */       results[i] = typeDataToBytes(data.m_arrData[i], desc.m_arrObj);
/*  585 */       totalLen += results[i].length;
/*      */     }
/*      */     
/*  588 */     totalLen += 20;
/*      */     
/*      */ 
/*  591 */     int total = data.m_objCount + data.m_strCount;
/*  592 */     if (total > 0) {
/*  593 */       totalLen += 2 * total;
/*      */     }
/*  595 */     rdata = realocBuffer(null, 0, totalLen);
/*      */     
/*      */ 
/*  598 */     Convertion.setInt(rdata, 0, totalLen);
/*  599 */     int offset = 4;
/*      */     
/*  601 */     Convertion.setInt(rdata, offset, data.m_arrData.length);
/*  602 */     offset += 4;
/*      */     
/*  604 */     Convertion.setInt(rdata, offset, 0);
/*  605 */     offset += 4;
/*      */     
/*  607 */     Convertion.setInt(rdata, offset, data.m_objCount);
/*  608 */     offset += 4;
/*      */     
/*  610 */     Convertion.setInt(rdata, offset, data.m_strCount);
/*  611 */     offset += 4;
/*      */     
/*  613 */     for (int i = 0; i < total; i++) {
/*  614 */       Convertion.setInt(rdata, offset, data.m_objStrOffs[i]);
/*  615 */       offset += 4;
/*      */     }
/*      */     
/*  618 */     for (int i = 0; i < data.m_arrData.length; i++) {
/*  619 */       System.arraycopy(results[i], 0, rdata, offset, results[i].length);
/*  620 */       offset += results[i].length;
/*      */     }
/*      */     
/*  623 */     return rdata;
/*      */   }
/*      */   
/*      */   public static byte[] objToBytes(STRUCT data, TypeDescriptor desc) throws SQLException
/*      */   {
/*  628 */     int size = desc.getStrctMemSize();
/*  629 */     byte[][] results = new byte[size][];
/*  630 */     byte[] rdata = null;
/*      */     
/*      */ 
/*  633 */     int totalLen = 0;
/*  634 */     for (int i = 0; i < size; i++) {
/*  635 */       results[i] = typeDataToBytes(data.m_attribs[i], desc.m_fieldsObj[i]);
/*  636 */       totalLen += results[i].length;
/*      */     }
/*      */     
/*  639 */     totalLen += 5;
/*      */     
/*  641 */     rdata = realocBuffer(null, 0, totalLen);
/*      */     
/*  643 */     int offset = 0;
/*      */     
/*  645 */     Convertion.setByte(rdata, offset, (byte)0);
/*  646 */     offset++;
/*      */     
/*      */ 
/*  649 */     Convertion.setInt(rdata, offset, totalLen);
/*  650 */     offset += 4;
/*      */     
/*  652 */     for (int i = 0; i < size; i++) {
/*  653 */       System.arraycopy(results[i], 0, rdata, offset, results[i].length);
/*  654 */       offset += results[i].length;
/*      */     }
/*      */     
/*  657 */     return rdata;
/*      */   }
/*      */   
/*      */   public static byte[] recordToBytes(STRUCT data, TypeDescriptor desc) throws SQLException
/*      */   {
/*  662 */     int size = desc.getStrctMemSize();
/*  663 */     byte[][] results = new byte[size][];
/*  664 */     byte[] rdata = null;
/*      */     
/*      */ 
/*  667 */     int totalLen = 0;
/*  668 */     for (int i = 0; i < size; i++) {
/*  669 */       results[i] = typeDataToBytes(data.m_attribs[i], desc.m_fieldsObj[i]);
/*  670 */       totalLen += results[i].length;
/*      */     }
/*      */     
/*  673 */     totalLen += 4;
/*  674 */     rdata = realocBuffer(null, 0, totalLen);
/*  675 */     Convertion.setInt(rdata, 0, totalLen);
/*      */     
/*  677 */     int offset = 4;
/*  678 */     for (int i = 0; i < desc.getStrctMemSize(); i++) {
/*  679 */       System.arraycopy(results[i], 0, rdata, offset, results[i].length);
/*  680 */       offset += results[i].length;
/*      */     }
/*      */     
/*  683 */     return rdata;
/*      */   }
/*      */   
/*      */   private static TypeData bytesToBlob(byte[] val, TypeData out, TypeDescriptor desc) throws SQLException
/*      */   {
/*  688 */     int offset = out.m_offset;
/*  689 */     int len = Convertion.getInt(val, offset);
/*  690 */     offset += 4;
/*      */     
/*  692 */     byte[] tmp = Convertion.getBytes(val, offset, len);
/*  693 */     offset += len;
/*  694 */     out.m_offset = offset;
/*      */     
/*  696 */     return new TypeData(new DmdbBlob(tmp, desc.m_conn), tmp);
/*      */   }
/*      */   
/*      */   private static TypeData bytesToClob(byte[] val, TypeData out, TypeDescriptor desc, String serverEncoding) throws SQLException
/*      */   {
/*  701 */     int offset = out.m_offset;
/*  702 */     int len = Convertion.getInt(val, offset);
/*  703 */     offset += 4;
/*      */     
/*  705 */     byte[] tmp = Convertion.getBytes(val, offset, len);
/*  706 */     offset += len;
/*  707 */     out.m_offset = offset;
/*      */     
/*  709 */     return new TypeData(new DmdbClob(tmp, desc.m_conn), tmp);
/*      */   }
/*      */   
/*      */   private static TypeData bytesToTypeData(byte[] val, TypeData out, TypeDescriptor desc)
/*      */     throws SQLException
/*      */   {
/*  715 */     int offset = out.m_offset;
/*      */     
/*  717 */     offset++;
/*      */     
/*  719 */     byte null_flag = Convertion.getByte(val, offset);
/*  720 */     offset++;
/*      */     
/*  722 */     out.m_offset = offset;
/*      */     
/*      */ 
/*  725 */     if (desc.getDType() == 13) {
/*  726 */       boolean b = false;
/*  727 */       if (null_flag != 0) {
/*  728 */         b = true;
/*      */       }
/*  730 */       return new TypeData(new Boolean(b), Convertion.getBytes(val, 
/*  731 */         offset - 1, 1));
/*      */     }
/*      */     
/*  734 */     Object retObj = null;
/*  735 */     byte[] retDataBuf = null;
/*  736 */     switch (desc.getDType()) {
/*      */     case 119: 
/*  738 */       if ((null_flag & 0x1) != 0) {
/*  739 */         retObj = bytesToObj(val, out, desc);
/*      */         
/*      */ 
/*  742 */         if (out.m_offset > offset) {
/*  743 */           retDataBuf = Convertion.getBytes(val, offset, out.m_offset - 
/*  744 */             offset);
/*      */         }
/*      */         
/*  747 */         return new TypeData(retObj, retDataBuf);
/*      */       }
/*  749 */       return new TypeData(null, null);
/*      */     
/*      */     case 117: 
/*  752 */       if ((null_flag & 0x1) != 0) {
/*  753 */         retObj = bytesToArray(val, out, desc);
/*      */         
/*  755 */         if (out.m_offset > offset) {
/*  756 */           retDataBuf = Convertion.getBytes(val, offset, out.m_offset - 
/*  757 */             offset);
/*      */         }
/*      */         
/*  760 */         return new TypeData(retObj, retDataBuf);
/*      */       }
/*  762 */       return new TypeData(null, null);
/*      */     
/*      */     case 121: 
/*  765 */       if ((null_flag & 0x1) != 0) {
/*  766 */         retObj = bytesToRecord(val, out, desc);
/*      */         
/*      */ 
/*  769 */         if (out.m_offset > offset) {
/*  770 */           retDataBuf = Convertion.getBytes(val, offset, out.m_offset - 
/*  771 */             offset);
/*      */         }
/*      */         
/*  774 */         return new TypeData(retObj, retDataBuf);
/*      */       }
/*  776 */       return new TypeData(null, null);
/*      */     
/*      */     case 122: 
/*  779 */       if ((null_flag & 0x1) != 0) {
/*  780 */         retObj = bytesToSArray(val, out, desc);
/*      */         
/*  782 */         if (out.m_offset > offset) {
/*  783 */           retDataBuf = Convertion.getBytes(val, offset, out.m_offset - 
/*  784 */             offset);
/*      */         }
/*      */         
/*  787 */         return new TypeData(retObj, retDataBuf);
/*      */       }
/*  789 */       return new TypeData(null, null);
/*      */     
/*      */     case 12: 
/*  792 */       if ((null_flag & 0x1) != 0) {
/*  793 */         return bytesToBlob(val, out, desc);
/*      */       }
/*  795 */       return new TypeData(null, null);
/*      */     
/*      */     case 19: 
/*  798 */       if ((null_flag & 0x1) != 0) {
/*  799 */         return bytesToClob(val, out, desc, desc.getServerEncoding());
/*      */       }
/*  801 */       return new TypeData(null, null);
/*      */     }
/*      */     
/*      */     
/*  805 */     if ((null_flag & 0x1) != 0) {
/*  806 */       CommDesc commDesc = new CommDesc();
/*  807 */       commDesc.getBaseInfo().setDTypeInfo(desc.m_dTypeInfo);
/*  808 */       commDesc.setLobDesc(desc.m_lobDesc);
/*  809 */       return convertBytes2BaseData(commDesc, val, out, desc.m_conn);
/*      */     }
/*  811 */     return new TypeData(null, null);
/*      */   }
/*      */   
/*      */ 
/*      */   private static boolean checkObjExist(byte[] val, TypeData out)
/*      */   {
/*  817 */     int offset = out.m_offset;
/*  818 */     byte exist_flag = Convertion.getByte(val, offset);
/*  819 */     offset++;
/*      */     
/*  821 */     out.m_offset = offset;
/*      */     
/*  823 */     if (exist_flag == 1) {
/*  824 */       return true;
/*      */     }
/*      */     
/*  827 */     out.m_offset += 4;
/*  828 */     return false;
/*      */   }
/*      */   
/*      */   private static STRUCT findObjByPackId(byte[] val, TypeData out)
/*      */     throws SQLException
/*      */   {
/*  834 */     int offset = out.m_offset;
/*      */     
/*  836 */     int pack_id = Convertion.getInt(val, offset);
/*  837 */     offset += 4;
/*      */     
/*  839 */     out.m_offset = offset;
/*      */     
/*      */ 
/*  842 */     if ((pack_id < 0) || (pack_id > out.m_packid)) {
/*  843 */       DBError.throwSQLException(6007);
/*      */     }
/*  845 */     return (STRUCT)out.m_objRefArr.get(pack_id);
/*      */   }
/*      */   
/*      */   private static void addObjToRefArr(TypeData out, Object objToAdd)
/*      */   {
/*  850 */     out.m_objRefArr.add(objToAdd);
/*      */     
/*  852 */     out.m_packid += 1;
/*      */   }
/*      */   
/*      */   private static boolean checkObjClnt(TypeDescriptor desc)
/*      */   {
/*  857 */     if (desc.m_objId == 4) {
/*  858 */       return true;
/*      */     }
/*  860 */     return false;
/*      */   }
/*      */   
/*      */   private static STRUCT bytesToObj_EXACT(byte[] val, TypeData out, TypeDescriptor desc)
/*      */     throws SQLException
/*      */   {
/*  866 */     STRUCT strOut = new STRUCT(null, desc);
/*      */     
/*      */ 
/*      */ 
/*  870 */     int offset = out.m_offset;
/*      */     
/*  872 */     int size = desc.getStrctMemSize();
/*      */     
/*      */ 
/*  875 */     out.m_offset = offset;
/*      */     
/*  877 */     strOut.m_attribs = new TypeData[size];
/*  878 */     for (int i = 0; i < size; i++) {
/*  879 */       TypeDescriptor sub_desc = desc.m_fieldsObj[i];
/*      */       
/*  881 */       strOut.m_attribs[i] = bytesToTypeData(val, out, sub_desc);
/*      */     }
/*      */     
/*  884 */     strOut.m_dataBuf = Convertion.getBytes(val, offset, out.m_offset - 
/*  885 */       offset);
/*      */     
/*  887 */     return strOut;
/*      */   }
/*      */   
/*      */   private static ARRAY bytesToNestTab(byte[] val, TypeData out, TypeDescriptor desc)
/*      */     throws SQLException
/*      */   {
/*  893 */     int offset = out.m_offset;
/*      */     
/*      */ 
/*      */ 
/*  897 */     offset += 2;
/*      */     
/*      */ 
/*  900 */     int count = Convertion.getInt(val, offset);
/*  901 */     offset += 4;
/*      */     
/*  903 */     out.m_offset = offset;
/*      */     
/*  905 */     ARRAY arrOut = new ARRAY(null, desc);
/*  906 */     arrOut.m_itemCount = count;
/*  907 */     arrOut.m_arrData = new TypeData[count];
/*  908 */     for (int i = 0; i < count; i++) {
/*  909 */       arrOut.m_arrData[i] = bytesToTypeData(val, out, desc.m_arrObj);
/*      */     }
/*  911 */     arrOut.m_dataBuf = Convertion.getBytes(val, offset, out.m_offset - 
/*  912 */       offset);
/*      */     
/*  914 */     return arrOut;
/*      */   }
/*      */   
/*      */   private static ARRAY bytesToClnt(byte[] val, TypeData out, TypeDescriptor desc) throws SQLException
/*      */   {
/*  919 */     ARRAY array = null;
/*      */     
/*  921 */     int offset = out.m_offset;
/*      */     
/*  923 */     int cltn_type = Convertion.getShort(val, offset);
/*  924 */     offset += 2;
/*      */     
/*  926 */     out.m_offset = offset;
/*  927 */     switch (cltn_type) {
/*      */     case 3: 
/*  929 */       DBError.throwUnsupportedSQLException();
/*  930 */       break;
/*      */     
/*      */     case 1: 
/*      */     case 2: 
/*  934 */       array = bytesToNestTab(val, out, desc);
/*      */     }
/*      */     
/*      */     
/*  938 */     return array;
/*      */   }
/*      */   
/*      */   public static Object bytesToObj(byte[] val, TypeData out, TypeDescriptor desc) throws SQLException
/*      */   {
/*  943 */     Object retObj = null;
/*  944 */     if (out == null) {
/*  945 */       out = new TypeData(null, null);
/*      */     }
/*  947 */     if (checkObjExist(val, out)) {
/*  948 */       retObj = findObjByPackId(val, out);
/*      */     }
/*      */     else {
/*  951 */       addObjToRefArr(out, retObj);
/*      */       
/*  953 */       if (checkObjClnt(desc)) {
/*  954 */         retObj = bytesToClnt(val, out, desc);
/*      */       } else {
/*  956 */         retObj = bytesToObj_EXACT(val, out, desc);
/*      */       }
/*      */     }
/*  959 */     return retObj;
/*      */   }
/*      */   
/*      */   public static ARRAY bytesToArray(byte[] val, TypeData out, TypeDescriptor desc)
/*      */     throws SQLException
/*      */   {
/*  965 */     ARRAY arrOut = new ARRAY(null, desc);
/*      */     
/*  967 */     if (out == null)
/*  968 */       out = new TypeData(null, null);
/*  969 */     int offset = out.m_offset;
/*      */     
/*  971 */     arrOut.m_bufLen = Convertion.getInt(val, offset);
/*  972 */     offset += 4;
/*      */     
/*      */ 
/*  975 */     arrOut.m_itemCount = Convertion.getInt(val, offset);
/*  976 */     offset += 4;
/*      */     
/*  978 */     arrOut.m_itemSize = Convertion.getInt(val, offset);
/*  979 */     offset += 4;
/*      */     
/*  981 */     arrOut.m_objCount = Convertion.getInt(val, offset);
/*  982 */     offset += 4;
/*      */     
/*  984 */     arrOut.m_strCount = Convertion.getInt(val, offset);
/*  985 */     offset += 4;
/*      */     
/*  987 */     int total = arrOut.m_objCount + arrOut.m_strCount;
/*  988 */     arrOut.m_objStrOffs = new int[total];
/*  989 */     for (int i = 0; i < total; i++) {
/*  990 */       arrOut.m_objStrOffs[i] = Convertion.getInt(val, offset);
/*  991 */       offset += 4;
/*      */     }
/*      */     
/*      */ 
/*  995 */     out.m_offset = offset;
/*      */     
/*      */ 
/*  998 */     arrOut.m_arrData = new TypeData[arrOut.m_itemCount];
/*  999 */     for (int i = 0; i < arrOut.m_itemCount; i++) {
/* 1000 */       arrOut.m_arrData[i] = bytesToTypeData(val, out, desc.m_arrObj);
/*      */     }
/* 1002 */     arrOut.m_dataBuf = Convertion.getBytes(val, offset, out.m_offset - 
/* 1003 */       offset);
/*      */     
/* 1005 */     return arrOut;
/*      */   }
/*      */   
/*      */   public static ARRAY bytesToSArray(byte[] val, TypeData out, TypeDescriptor desc) throws SQLException
/*      */   {
/* 1010 */     if (out == null)
/* 1011 */       out = new TypeData(null, null);
/* 1012 */     int offset = out.m_offset;
/*      */     
/* 1014 */     ARRAY arrOut = new ARRAY(null, desc);
/*      */     
/* 1016 */     arrOut.m_bufLen = Convertion.getInt(val, offset);
/* 1017 */     offset += 4;
/*      */     
/*      */ 
/* 1020 */     arrOut.m_itemCount = Convertion.getInt(val, offset);
/* 1021 */     offset += 4;
/*      */     
/*      */ 
/* 1024 */     out.m_offset = offset;
/*      */     
/* 1026 */     arrOut.m_arrData = new TypeData[arrOut.m_itemCount];
/* 1027 */     for (int i = 0; i < arrOut.m_itemCount; i++) {
/* 1028 */       arrOut.m_arrData[i] = bytesToTypeData(val, out, desc.m_arrObj);
/*      */     }
/* 1030 */     arrOut.m_dataBuf = Convertion.getBytes(val, offset, out.m_offset - 
/* 1031 */       offset);
/*      */     
/* 1033 */     return arrOut;
/*      */   }
/*      */   
/*      */   public static STRUCT bytesToRecord(byte[] val, TypeData out, TypeDescriptor desc) throws SQLException
/*      */   {
/* 1038 */     if (out == null)
/* 1039 */       out = new TypeData(null, null);
/* 1040 */     int offset = out.m_offset;
/*      */     
/* 1042 */     STRUCT strOut = new STRUCT(null, desc);
/*      */     
/* 1044 */     strOut.m_bufLen = Convertion.getInt(val, offset);
/* 1045 */     offset += 4;
/*      */     
/*      */ 
/* 1048 */     out.m_offset = offset;
/*      */     
/* 1050 */     strOut.m_attribs = new TypeData[desc.getStrctMemSize()];
/* 1051 */     for (int i = 0; i < desc.getStrctMemSize(); i++) {
/* 1052 */       strOut.m_attribs[i] = bytesToTypeData(val, out, desc.m_fieldsObj[i]);
/*      */     }
/* 1054 */     strOut.m_dataBuf = Convertion.getBytes(val, offset, out.m_offset - 
/* 1055 */       offset);
/*      */     
/* 1057 */     return strOut;
/*      */   }
/*      */   
/*      */ 
/*      */   private static void objBlob_GetChkBuf(byte[] buf, TypeData typeData)
/*      */   {
/* 1063 */     int offset = 4;
/*      */     
/*      */ 
/* 1066 */     int len = Convertion.getInt(buf, offset);
/* 1067 */     offset += 4;
/*      */     
/*      */ 
/* 1070 */     typeData.m_objBlobDescBuf = Convertion.getBytes(buf, offset, len);
/* 1071 */     offset += len;
/*      */     
/* 1073 */     typeData.m_isFromBlob = true;
/*      */     
/*      */ 
/* 1076 */     typeData.m_offset = offset;
/*      */   }
/*      */   
/*      */   public static Object objBlobToObj(Blob lob, TypeDescriptor desc)
/*      */     throws SQLException
/*      */   {
/* 1082 */     TypeData typeData = new TypeData(null, null);
/* 1083 */     int loblen = (int)lob.length();
/* 1084 */     byte[] buf = lob.getBytes(1L, loblen);
/*      */     
/*      */ 
/* 1087 */     objBlob_GetChkBuf(buf, typeData);
/*      */     
/* 1089 */     return bytesToObj(buf, typeData, desc);
/*      */   }
/*      */   
/*      */   public static byte[] objBlobToBytes(byte[] lobBuf, TypeDescriptor desc)
/*      */     throws SQLException
/*      */   {
/* 1095 */     int len = lobBuf.length;
/* 1096 */     byte[] buf = lobBuf;
/* 1097 */     int offset = 0;
/*      */     
/*      */ 
/* 1100 */     int magic = Convertion.getInt(buf, offset);
/* 1101 */     offset += 4;
/*      */     
/* 1103 */     if (78111999 != magic) {
/* 1104 */       DBError.throwSQLException(
/* 1105 */         Const.res.getString("error.invalidObjBlob"));
/*      */     }
/*      */     
/* 1108 */     int descLen = Convertion.getInt(buf, offset);
/* 1109 */     offset += 4;
/*      */     
/* 1111 */     byte[] descBuf = Convertion.getBytes(buf, offset, descLen);
/* 1112 */     if (Comparison.compareBytes(descBuf, desc.getClassDescChkInfo()) != 0)
/* 1113 */       DBError.throwSQLException(
/* 1114 */         Const.res.getString("error.invalidObjBlob"));
/* 1115 */     offset += descLen;
/*      */     
/*      */ 
/* 1118 */     byte[] ret = new byte[len - offset];
/* 1119 */     System.arraycopy(buf, offset, ret, 0, ret.length);
/*      */     
/* 1121 */     return ret;
/*      */   }
/*      */   
/*      */   private static byte[] realocBuffer(byte[] oldBuf, int offset, int needLen) {
/* 1125 */     byte[] retBuf = null;
/*      */     
/* 1127 */     if (oldBuf == null) {
/* 1128 */       return new byte[needLen];
/*      */     }
/* 1130 */     if (needLen + offset > oldBuf.length) {
/* 1131 */       retBuf = new byte[oldBuf.length + needLen];
/* 1132 */       System.arraycopy(oldBuf, 0, retBuf, 0, offset);
/*      */     } else {
/* 1134 */       retBuf = oldBuf;
/*      */     }
/* 1136 */     return retBuf;
/*      */   }
/*      */   
/*      */   private static TypeData convertBytes2BaseData(CommDesc desc, byte[] val, TypeData out, DmdbConnection_bs conn)
/*      */     throws SQLException
/*      */   {
/* 1142 */     int dType = desc.getDType();
/* 1143 */     int scale = desc.getScale();
/*      */     
/* 1145 */     int offset = out.m_offset;
/*      */     
/* 1147 */     boolean isNull = false;
/* 1148 */     int valueLen = Convertion.getShort(val, offset);
/* 1149 */     offset += 2;
/*      */     
/* 1151 */     if (valueLen == 65534) {
/* 1152 */       valueLen = 0;
/* 1153 */       isNull = true;
/*      */     }
/*      */     
/* 1156 */     if (-1 == valueLen) {
/* 1157 */       valueLen = Convertion.getInt(val, offset);
/* 1158 */       offset += 4;
/*      */     }
/*      */     
/* 1161 */     if (isNull) {
/* 1162 */       out.m_offset = offset;
/* 1163 */       return new TypeData(null, null);
/*      */     }
/*      */     
/* 1166 */     Object tmpObj = null;
/* 1167 */     byte[] temp = Convertion.getBytes(val, offset, valueLen);
/* 1168 */     offset += valueLen;
/* 1169 */     out.m_offset = offset;
/*      */     
/* 1171 */     switch (dType) {
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/* 1175 */       tmpObj = CType2JType.getString(temp, desc, 0, conn, false);
/* 1176 */       break;
/*      */     
/*      */     case 3: 
/*      */     case 5: 
/* 1180 */       tmpObj = new Byte(CType2JType.getByte(temp, desc, 0, conn));
/* 1181 */       break;
/*      */     
/*      */     case 6: 
/* 1184 */       tmpObj = new Short(CType2JType.getShort(temp, desc, 0, conn));
/* 1185 */       break;
/*      */     
/*      */     case 7: 
/* 1188 */       tmpObj = new Integer(CType2JType.getInt(temp, desc, 0, conn));
/* 1189 */       break;
/*      */     
/*      */     case 8: 
/* 1192 */       tmpObj = new Long(CType2JType.getLong(temp, desc, 0, conn));
/* 1193 */       break;
/*      */     
/*      */     case 9: 
/*      */     case 24: 
/* 1197 */       tmpObj = CType2JType.getBigDecimal(temp, desc, 0, conn);
/* 1198 */       break;
/*      */     
/*      */     case 10: 
/* 1201 */       tmpObj = new Float(CType2JType.getFloat(temp, desc, 0, conn));
/* 1202 */       break;
/*      */     
/*      */     case 11: 
/* 1205 */       tmpObj = new Double(CType2JType.getDouble(temp, desc, 0, conn));
/* 1206 */       break;
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */     case 14: 
/* 1212 */       tmpObj = CType2JType.getDate(temp, desc, 0, conn);
/* 1213 */       break;
/*      */     
/*      */     case 15: 
/* 1216 */       tmpObj = CType2JType.getTime(temp, desc, 0, conn);
/* 1217 */       break;
/*      */     
/*      */     case 4: 
/*      */     case 17: 
/*      */     case 18: 
/* 1222 */       tmpObj = CType2JType.getBytes(temp, desc, 0, conn);
/* 1223 */       break;
/*      */     
/*      */     case 16: 
/* 1226 */       tmpObj = CType2JType.getTimestamp(temp, desc, 0, conn);
/* 1227 */       break;
/*      */     
/*      */     case 20: 
/* 1230 */       tmpObj = CType2JType.getIntervalYM(temp, desc, 0, conn, false);
/* 1231 */       break;
/*      */     
/*      */     case 21: 
/* 1234 */       tmpObj = CType2JType.getIntervalDT(temp, desc, 0, conn, false);
/* 1235 */       break;
/*      */     
/*      */     case 22: 
/* 1238 */       tmpObj = Convertion.bytesToTimeZone(temp, scale);
/* 1239 */       break;
/*      */     
/*      */     case 23: 
/* 1242 */       tmpObj = Convertion.bytesToDateTimeZone(temp, scale);
/* 1243 */       break;
/*      */     case 12: case 13: 
/*      */     case 19: default: 
/* 1246 */       DBError.throwUnsupportedSQLException();
/* 1247 */       tmpObj = null;
/*      */     }
/*      */     
/* 1250 */     return new TypeData(tmpObj, temp);
/*      */   }
/*      */   
/*      */   public Object toJavaArray(ARRAY arr, int len, int dType) throws SQLException
/*      */   {
/* 1255 */     return toJavaArray(arr, 1L, len, dType);
/*      */   }
/*      */   
/*      */   public Object toJavaArray(ARRAY arr, long index, int len, int dType) throws SQLException
/*      */   {
/* 1260 */     if (arr.m_objArray != null) {
/* 1261 */       return arr.m_objArray;
/*      */     }
/* 1263 */     Object nr = null;
/* 1264 */     int realIdx = (int)(index - 1L);
/* 1265 */     TypeData tempData = null;
/* 1266 */     switch (dType) {
/*      */     case 0: 
/*      */     case 1: 
/*      */     case 2: 
/* 1270 */       nr = new String[len];
/* 1271 */       for (int i = 0; i < len; i++) {
/* 1272 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1273 */         if ((tempData != null) && (tempData.m_dumyData != null))
/* 1274 */           ((String[])nr)[i] = new String(
/* 1275 */             (String)tempData.m_dumyData);
/*      */       }
/* 1277 */       break;
/*      */     
/*      */     case 4: 
/*      */     case 17: 
/*      */     case 18: 
/* 1282 */       nr = new byte[len];
/* 1283 */       for (int i = 0; i < len; i++) {
/* 1284 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1285 */         if ((tempData != null) && (tempData.m_dumyData != null)) {
/* 1286 */           byte[] temp = (byte[])tempData.m_dumyData;
/* 1287 */           if (temp.length > 0)
/* 1288 */             ((byte[])nr)[i] = temp[0];
/*      */         }
/*      */       }
/* 1291 */       break;
/*      */     
/*      */     case 13: 
/* 1294 */       nr = new Boolean[len];
/* 1295 */       for (int i = 0; i < len; i++) {
/* 1296 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1297 */         if ((tempData != null) && (tempData.m_dumyData != null)) {
/* 1298 */           ((Boolean[])nr)[i] = new Boolean(
/* 1299 */             ((Boolean)tempData.m_dumyData).booleanValue());
/*      */         } else
/* 1301 */           ((Boolean[])nr)[i] = new Boolean(false);
/*      */       }
/* 1303 */       break;
/*      */     
/*      */     case 3: 
/*      */     case 5: 
/* 1307 */       nr = new Byte[len];
/* 1308 */       for (int i = 0; i < len; i++) {
/* 1309 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1310 */         if ((tempData != null) && (tempData.m_dumyData != null)) {
/* 1311 */           ((Byte[])nr)[i] = new Byte(
/* 1312 */             ((Byte)tempData.m_dumyData).byteValue());
/*      */         } else
/* 1314 */           ((Byte[])nr)[i] = new Byte(0);
/*      */       }
/* 1316 */       break;
/*      */     
/*      */     case 6: 
/* 1319 */       nr = new Short[len];
/* 1320 */       for (int i = 0; i < len; i++) {
/* 1321 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1322 */         if ((tempData != null) && (tempData.m_dumyData != null)) {
/* 1323 */           ((Short[])nr)[i] = new Short(
/* 1324 */             ((Short)tempData.m_dumyData).shortValue());
/*      */         } else
/* 1326 */           ((Short[])nr)[i] = new Short(0);
/*      */       }
/* 1328 */       break;
/*      */     
/*      */     case 7: 
/* 1331 */       nr = new Integer[len];
/* 1332 */       for (int i = 0; i < len; i++) {
/* 1333 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1334 */         if ((tempData != null) && (tempData.m_dumyData != null)) {
/* 1335 */           ((Integer[])nr)[i] = new Integer(
/* 1336 */             ((Integer)tempData.m_dumyData).intValue());
/*      */         } else
/* 1338 */           ((Integer[])nr)[i] = new Integer(0);
/*      */       }
/* 1340 */       break;
/*      */     
/*      */     case 8: 
/* 1343 */       nr = new Long[len];
/* 1344 */       for (int i = 0; i < len; i++) {
/* 1345 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1346 */         if ((tempData != null) && (tempData.m_dumyData != null)) {
/* 1347 */           ((Long[])nr)[i] = new Long(
/* 1348 */             ((Long)tempData.m_dumyData).longValue());
/*      */         } else
/* 1350 */           ((Long[])nr)[i] = new Long(0L);
/*      */       }
/* 1352 */       break;
/*      */     
/*      */     case 9: 
/*      */     case 24: 
/* 1356 */       nr = new BigDecimal[len];
/* 1357 */       for (int i = 0; i < len; i++) {
/* 1358 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1359 */         if ((tempData != null) && (tempData.m_dumyData != null)) {
/* 1360 */           ((BigDecimal[])nr)[i] = new BigDecimal(
/* 1361 */             String.valueOf(tempData.m_dumyData));
/*      */         } else
/* 1363 */           ((BigDecimal[])nr)[i] = new BigDecimal(0.0D);
/*      */       }
/* 1365 */       break;
/*      */     
/*      */     case 10: 
/* 1368 */       nr = new Float[len];
/* 1369 */       for (int i = 0; i < len; i++) {
/* 1370 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1371 */         if ((tempData != null) && (tempData.m_dumyData != null)) {
/* 1372 */           ((Float[])nr)[i] = new Float(
/* 1373 */             ((Float)tempData.m_dumyData).floatValue());
/*      */         } else
/* 1375 */           ((Float[])nr)[i] = new Float(0.0F);
/*      */       }
/* 1377 */       break;
/*      */     
/*      */     case 11: 
/* 1380 */       nr = new Double[len];
/* 1381 */       for (int i = 0; i < len; i++) {
/* 1382 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1383 */         if ((tempData != null) && (tempData.m_dumyData != null)) {
/* 1384 */           ((Double[])nr)[i] = new Double(
/* 1385 */             ((Double)tempData.m_dumyData).doubleValue());
/*      */         } else
/* 1387 */           ((Double[])nr)[i] = new Double(0.0D);
/*      */       }
/* 1389 */       break;
/*      */     
/*      */     case 14: 
/* 1392 */       nr = new java.sql.Date[len];
/* 1393 */       for (int i = 0; i < len; i++) {
/* 1394 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1395 */         if ((tempData != null) && (tempData.m_dumyData != null))
/* 1396 */           ((java.sql.Date[])nr)[i] = ((java.sql.Date)tempData.m_dumyData);
/*      */       }
/* 1398 */       break;
/*      */     
/*      */     case 15: 
/* 1401 */       nr = new Time[len];
/* 1402 */       for (int i = 0; i < len; i++) {
/* 1403 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1404 */         if ((tempData != null) && (tempData.m_dumyData != null))
/* 1405 */           ((Time[])nr)[i] = ((Time)tempData.m_dumyData);
/*      */       }
/* 1407 */       break;
/*      */     
/*      */     case 16: 
/* 1410 */       nr = new Timestamp[len];
/* 1411 */       for (int i = 0; i < len; i++) {
/* 1412 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1413 */         if ((tempData != null) && (tempData.m_dumyData != null))
/* 1414 */           ((Timestamp[])nr)[i] = ((Timestamp)tempData.m_dumyData);
/*      */       }
/* 1416 */       break;
/*      */     
/*      */     case 20: 
/* 1419 */       nr = new DmdbIntervalYM[len];
/* 1420 */       for (int i = 0; i < len; i++) {
/* 1421 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1422 */         if ((tempData != null) && (tempData.m_dumyData != null))
/* 1423 */           ((DmdbIntervalYM[])nr)[i] = ((DmdbIntervalYM)tempData.m_dumyData);
/*      */       }
/* 1425 */       break;
/*      */     
/*      */     case 21: 
/* 1428 */       nr = new DmdbIntervalDT[len];
/* 1429 */       for (int i = 0; i < len; i++) {
/* 1430 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1431 */         if ((tempData != null) && (tempData.m_dumyData != null))
/* 1432 */           ((DmdbIntervalDT[])nr)[i] = ((DmdbIntervalDT)tempData.m_dumyData);
/*      */       }
/* 1434 */       break;
/*      */     
/*      */     case 22: 
/*      */     case 23: 
/* 1438 */       nr = new DmdbTimeZone[len];
/* 1439 */       for (int i = 0; i < len; i++) {
/* 1440 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1441 */         if ((tempData != null) && (tempData.m_dumyData != null))
/* 1442 */           ((DmdbTimeZone[])nr)[i] = ((DmdbTimeZone)tempData.m_dumyData);
/*      */       }
/* 1444 */       break;
/*      */     
/*      */     case 119: 
/*      */     case 121: 
/* 1448 */       nr = new STRUCT[len];
/* 1449 */       for (int i = 0; i < len; i++) {
/* 1450 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1451 */         if ((tempData != null) && (tempData.m_dumyData != null)) {
/* 1452 */           ((STRUCT[])nr)[i] = ((STRUCT)tempData.m_dumyData);
/*      */         } else
/* 1454 */           ((STRUCT[])nr)[i] = null;
/*      */       }
/* 1456 */       break;
/*      */     
/*      */     case 117: 
/*      */     case 122: 
/* 1460 */       nr = new ARRAY[len];
/* 1461 */       for (int i = 0; i < len; i++) {
/* 1462 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1463 */         if ((tempData != null) && (tempData.m_dumyData != null)) {
/* 1464 */           ((ARRAY[])nr)[i] = ((ARRAY)tempData.m_dumyData);
/*      */         } else
/* 1466 */           ((ARRAY[])nr)[i] = null;
/*      */       }
/* 1468 */       break;
/*      */     
/*      */     case 12: 
/* 1471 */       nr = new DmdbBlob[len];
/* 1472 */       for (int i = 0; i < len; i++) {
/* 1473 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1474 */         if ((tempData != null) && (tempData.m_dumyData != null)) {
/* 1475 */           ((DmdbBlob[])nr)[i] = 
/* 1476 */             ((DmdbBlob)((DmdbBlob)tempData.m_dumyData).clone());
/*      */         } else
/* 1478 */           ((DmdbBlob[])nr)[i] = null;
/*      */       }
/* 1480 */       break;
/*      */     
/*      */     case 19: 
/* 1483 */       nr = new DmdbClob[len];
/* 1484 */       for (int i = 0; i < len; i++) {
/* 1485 */         tempData = arr.m_arrData[(realIdx + i)];
/* 1486 */         if ((tempData != null) && (tempData.m_dumyData != null)) {
/* 1487 */           ((DmdbClob[])nr)[i] = 
/* 1488 */             ((DmdbClob)((DmdbClob)tempData.m_dumyData).clone());
/*      */         } else
/* 1490 */           ((DmdbClob[])nr)[i] = null;
/*      */       }
/* 1492 */       break;
/*      */     
/*      */     default: 
/* 1495 */       DBError.throwUnsupportedSQLException();
/* 1496 */       return null;
/*      */     }
/*      */     
/* 1499 */     return nr;
/*      */   }
/*      */   
/*      */   Object toNumericArray(ARRAY arr, long index, int len, int flag) throws SQLException
/*      */   {
/* 1504 */     if (arr.m_objArray == null) {
/* 1505 */       return null;
/*      */     }
/* 1507 */     int realIdx = (int)(index - 1L);
/* 1508 */     Object retObj = null;
/* 1509 */     if ((flag == 1) && 
/* 1510 */       ((arr.m_objArray instanceof short[]))) {
/* 1511 */       short[] ret = new short[len];
/* 1512 */       System.arraycopy(arr.m_objArray, realIdx, ret, 0, len);
/* 1513 */       retObj = ret;
/* 1514 */     } else if ((flag == 2) && 
/* 1515 */       ((arr.m_objArray instanceof int[]))) {
/* 1516 */       int[] ret = new int[len];
/* 1517 */       System.arraycopy(arr.m_objArray, realIdx, ret, 0, len);
/* 1518 */       retObj = ret;
/* 1519 */     } else if ((flag == 3) && 
/* 1520 */       ((arr.m_objArray instanceof long[]))) {
/* 1521 */       long[] ret = new long[len];
/* 1522 */       System.arraycopy(arr.m_objArray, realIdx, ret, 0, len);
/* 1523 */       retObj = ret;
/* 1524 */     } else if ((flag == 4) && 
/* 1525 */       ((arr.m_objArray instanceof float[]))) {
/* 1526 */       float[] ret = new float[len];
/* 1527 */       System.arraycopy(arr.m_objArray, realIdx, ret, 0, len);
/* 1528 */       retObj = ret;
/* 1529 */     } else if ((flag == 5) && 
/* 1530 */       ((arr.m_objArray instanceof double[]))) {
/* 1531 */       double[] ret = new double[len];
/* 1532 */       System.arraycopy(arr.m_objArray, realIdx, ret, 0, len);
/* 1533 */       retObj = ret;
/*      */     }
/*      */     
/* 1536 */     DBError.throwSQLException(6007);
/*      */     
/* 1538 */     return retObj;
/*      */   }
/*      */   
/*      */   Object toJava(Object value, Map map) {
/* 1542 */     return value;
/*      */   }
/*      */   
/*      */   Object[] toJavaArray(STRUCT struct) throws SQLException {
/* 1546 */     TypeData[] attrsData = struct.getAttribsTypeData();
/* 1547 */     if ((struct.getAttribsTypeData() == null) || 
/* 1548 */       (struct.getAttribsTypeData().length <= 0)) {
/* 1549 */       return null;
/*      */     }
/*      */     
/* 1552 */     TypeDescriptor[] fields = struct.m_strctDesc.getItemsDesc();
/* 1553 */     if (attrsData.length != fields.length) {
/* 1554 */       throw new SQLException(
/* 1555 */         Const.res.getString("error.structMemNotMatch"));
/*      */     }
/* 1557 */     Object[] out = new Object[fields.length];
/* 1558 */     for (int i = 0; i < fields.length; i++) {
/* 1559 */       out[i] = toJava(attrsData[i].m_dumyData, null);
/*      */     }
/* 1561 */     return out;
/*      */   }
/*      */ }


/* Location:              D:\Program Files\DBMS_20150813\jdbc\Dm7JdbcDriver17.jar!\dm\sql\TypeData.class
 * Java compiler version: 2 (46.0)
 * JD-Core Version:       0.7.1
 */